package com.ruoyi.common.utils;

import com.alibaba.druid.filter.config.ConfigTools;

/**
 * 配置文件中数据库连接的密码加密类
 * 文件中保留了加密使用的公钥和私钥，可以进行加解密
 *
 * @author yinjc
 */
public class ConfigToolsTest {

    /**
     * 公钥(用于解密)
     */
    private static final String RSA_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKCutnWrGC6NwVZiIJbh/4GZjc7Ty44E+yZdA7m7RnM5Qfgx9LWZNL6rKqGC46uJI2EWVQy65Tcg+0oinyyR5+kCAwEAAQ==";

    /**
     * 私钥(用于加密)
     */
    private static final String RSA_PRIVATE_KEY = "MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAoK62dasYLo3BVmIgluH/gZmNztPLjgT7Jl0DubtGczlB+DH0tZk0vqsqoYLjq4kjYRZVDLrlNyD7SiKfLJHn6QIDAQABAkEAhlpPuge7ioGA3UfjVAXX7HeGeR/infdQQH2Ztdz/RSuRAgOnmrc0gOlBTH6zH5128KCoVY3QL3CV80nfZTctOQIhANpjgfGBleXZduU7E4Gtpkd5tfAAxdOXBFceUX2+uat7AiEAvFsB8lYrK7nocGPr9c/zhATw4tE7uZOgH+NGiWD1GusCIF1NC/QA1+il+qy+i3vok1SQBBGwUtQt/bW2hzxAopRHAiEAsyrOmzokLp/U3rPtzBFXTol0qgzlhw1KD4sdmahE/qkCIHi1jc5P08ZjfXHx5loUTjLCAiZsuyxrm2/Et9S6hYUW";

    /**
     *
     * 要加密的密码
     */
    private static final String PASSWORD = "tgmc";

    /**
     *
     * 加密后的密码
     */
    private static final String mi_PASSWORD = "IdOASCxtPNfSyRkYKNURVdLJColAmi8HQoqM72LVJQRsO8goOymObM5xyXj2HOtyghePBpmd9cjzr56E20MEKw==";

    public static void main(String[] args) throws Exception {
        String encryptPassword = ConfigTools.encrypt(RSA_PRIVATE_KEY, PASSWORD);
        System.out.println("encryptPassword=" + encryptPassword);

        String decryptPassword = ConfigTools.decrypt(RSA_PUBLIC_KEY, mi_PASSWORD);
        System.out.println("decryptPassword=" + decryptPassword);
    }

}
